package com.weactivity.mapper;

import com.weactivity.dto.ApproveDTO;
import com.weactivity.entity.Budget;
import com.weactivity.entity.Expense;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BudgetMapper {
    @Insert("insert into budget(aid, name, total_budget, remain) value(#{aid},#{name},#{totalBudget},#{remain})" )
    void add(Budget budget);

    @Select("select total_budget from budget where aid = #{aid}")
    double findBudget(int aid);

    @Select("select remain from budget where aid = #{aid}")
    double findRemain(int aid);
    

    @Select("select * from budget")
    List<Budget> showAll();

    @Insert("insert into expense(uid, aid, money, reason, approve, state) "+
    "value (#{uid},#{aid},#{money},#{reason},#{approve},#{state})")
    void apply(Expense expense);

    List<Expense> showApply(int state);
    
    @Select("select money from expense where uid=#{uid} and aid=#{aid}")
    double findMoney(ApproveDTO approveDTO);

    void dispose(Budget budget);

    void updateBudget(Budget budget);

    void updateState(Expense expense);
}
